/**
 * 数据库连接
 */

const mongoose = require('mongoose');
const config = require('../../kum.config');
const log4js = require('./log4j');

mongoose.connect(config.DB_URL, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

const db = mongoose.connection;

// 监听数据库错误
db.on('error', (error) => {
  log4js.error(error);
});

// 成功告知成功
db.on('open', () => {
  log4js.info('***数据库连接成功***');
});
